/**
 * 
 */
package edu.cmu.mism.dgjava.data.ui.tree;

import org.eclipse.core.runtime.Assert;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;

import edu.cmu.mism.dgjava.algorithm.impl.TreeNode;

/**
 * Tree node figure that represents a tree node in the diagram
 * 
 * @author Christian
 * 
 */
public class TreeNodeFigure extends Figure {
	public static Color nodeColor = new Color(null, 255, 255, 215);
	public static Color execColor = Display.getDefault().getSystemColor(
			SWT.COLOR_RED);
	public static final int DEFAULT_WIDTH = 80;
	public static final int DEFAULT_HEIGHT = 35;

	private TreeNode node;

	// strike price section figure
	private TreeLabelSectionFigure strickPriceFigure = new TreeLabelSectionFigure();

	// option price section figure
	private TreeLabelSectionFigure optionPriceFigure = new TreeLabelSectionFigure();

	public TreeNodeFigure(TreeNode node) {
		this.node = node;

		ToolbarLayout layout = new ToolbarLayout();
		setLayoutManager(layout);
		setBorder(new LineBorder(ColorConstants.black, 1));
		setBackgroundColor(nodeColor);
		setOpaque(true);

		add(strickPriceFigure);
		add(optionPriceFigure);

		if (node != null) {
			strickPriceFigure.add(new Label("" + this.node.stockPrice));

			Label opLbl = new Label("" + this.node.optionPrice);
			if (this.node.canExercise) {
				opLbl.setForegroundColor(execColor);
			}
			optionPriceFigure.add(opLbl);

		}

	}

	public TreeLabelSectionFigure getStrickPriceSectionFigure() {
		return strickPriceFigure;
	}

	public TreeLabelSectionFigure getOptionPriceSectionFigure() {
		return optionPriceFigure;
	}

	public TreeNode getSemanticModel() {
		return node;
	}
}
